﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Aludra.Core.Models
{
    public class FieldCardZone
    {
        public SpellTrapCard FieldCard
        {
            get;
            private set;
        }

        #region IField Members
        public FieldType FieldType
        {
            get { return FieldType.FieldCardZone; }
        }

        public int Size
        {
            get { return 1; }
        }

        public event EventHandler<CardsRemovedEventArgs> CardsRemoved;

        public event EventHandler<CardsAddedEventArgs> CardsAdded;

        #endregion

        public bool Add(SpellTrapCard item)
        {
            if (item == null || item.SpellTrapType != SpellTrapType.FieldSpell)
            {
                return false;
            }

            this.FieldCard = item;
            EventHandler<CardsAddedEventArgs> tempAdded = this.CardsAdded;
            if (tempAdded != null)
            {
                tempAdded(this, new CardsAddedEventArgs(this.FieldType, new[] { this.FieldCard }));
            }
            return true;
        }

        public void Remove()
        {
            if (this.FieldCard != null)
            {
                // Copy to a temporary variable to be thread-safe.
                EventHandler<CardsRemovedEventArgs> temp = CardsRemoved;
                if (temp != null)
                {
                    temp(this, new CardsRemovedEventArgs(this.FieldType, new[] { this.FieldCard }));
                }
                this.FieldCard = null;
            }
        }
    }
}
